//
//  CustomJourTableCell.m
//  YouGoWeGo
//
//  Created by LiuFei on 14/11/20.
//  Copyright (c) 2014年 LiuFei. All rights reserved.
//

#import "CustomJourTableCell.h"

#import "AreaModel.h"
#import "UIImageView+WebCache.h"
@implementation CustomJourTableCell

- (void)dealloc
{
    [_model release];
    [_image release];
    [_timeLabel release];
    [_regionLabel release];
    [_contentLabel release];
    [self removeObserver:self forKeyPath:@"model"];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"2.png"]];
        [_image setFrame:CGRectMake(30, 20, self.frame.size.width, [UIScreen mainScreen].bounds.size.height / 3)];
        [self addSubview:_image];
        [_image release];
        
        self.contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, self.image.frame.size.height + 10, [UIScreen mainScreen].bounds.size.width - 10, [UIScreen mainScreen].bounds.size.height / 4 / 4 * 3)];
        [_contentLabel setNumberOfLines:0];
        [self addSubview:_contentLabel];
        [_contentLabel release];
        
        self.timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, self.image.frame.size.height + _contentLabel.frame.size.height, [UIScreen mainScreen].bounds.size.width / 4, [UIScreen mainScreen].bounds.size.height / 4 / 4)];
        [self addSubview:_timeLabel];
        [_timeLabel release];
        
        self.regionLabel = [[UILabel alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width / 4 * 3, self.image.frame.size.height + _contentLabel.frame.size.height, [UIScreen mainScreen].bounds.size.width / 4, [UIScreen mainScreen].bounds.size.height / 4 / 4)];
        [self addSubview:_regionLabel];
        [_regionLabel release];
        
        [self addObserver:self forKeyPath:@"model" options:NSKeyValueObservingOptionNew context:nil];
    }
    return self;
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    if ([keyPath isEqualToString:@"model"]) {
        
        [self.image setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", self.model.photo_s]]];
        self.contentLabel.text = self.model.text;
        self.regionLabel.text = self.model.city;
        self.timeLabel.text = self.model.local_time;
        
    }
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
